From 3cd7708774f74b137f0fff76d7f9d0ebd9754485 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Tue, 6 Mar 2018 09:30:37 +0000 Subject: [PATCH] Neater error message. Tests now check the cycle is output. --- src/cargo/core/resolver/mod.rs | 8 ++++++-- tests/testsuite/build.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index 402dd42a6..234646b3a 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -1491,8 +1491,12 @@ fn check_cycles(resolve: &Resolve, activations: &Activations) -> CargoResult<()> { // See if we visited ourselves if !visited.insert(id) { - bail!("cyclic package dependency: package `{}` depends on itself. Cycle (not in order): {:#?}", - id, visited); + let mut cycle = String::new(); + for package_id in visited.iter() { + cycle += &format!("\n {}", package_id); + } + bail!("cyclic package dependency: package `{}` depends on itself. Cycle (not in order):{}", + id, cycle); } // If we've already checked this node no need to recurse again as we'll diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index d7049befa..f7f2d532b 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -1532,7 +1532,9 @@ fn self_dependency() { assert_that(p.cargo("build"), execs().with_status(101) .with_stderr_contains("\ -[ERROR] cyclic package dependency: package `test v0.0.0 ([..])` depends on itself[..]")); +[ERROR] cyclic package dependency: package `test v0.0.0 ([..])` depends on itself. Cycle (not in order): + test v0.0.0 ([..][/]foo) +")); } #[test] @@ -2653,7 +2655,10 @@ fn cyclic_deps_rejected() { execs().with_status(101) .with_stderr_contains("\ [ERROR] cyclic package dependency: package `a v0.0.1 ([..]") - .with_stderr_contains("[..]depends on itself[..]")); + .with_stderr_contains("[..]depends on itself[..]") + .with_stderr_contains(" foo v0.0.1 ([..][/]foo)") + .with_stderr_contains(" a v0.0.1 ([..][/]a)")); + } #[test] -- 2.30.2